Skip to content

OAuth2: PKCE(Proof Key for Code Exchange)#37849

Merged
wbpcode merged 32 commits intoenvoyproxy:mainfrom
zhaohuabing:api-ouath-pkce
Mar 26, 2025
Merged

OAuth2: PKCE(Proof Key for Code Exchange)#37849
wbpcode merged 32 commits intoenvoyproxy:mainfrom
zhaohuabing:api-ouath-pkce

Conversation

@zhaohuabing
Copy link
Copy Markdown
Member

@zhaohuabing zhaohuabing commented Jan 2, 2025

This PR introduces support for PKCE(Proof Key for Code Exchange) in the OAuth2 filter. This enhancement mitigates the risk of the authorization code interception attacks.

Background: https://oauth.net/2/pkce/
RFC: Proof Key for Code Exchange by OAuth Public Clients

Commit Message:
Additional Description:
Risk Level: low
Testing: unit and integrate test, also manually tested with AWS cognito
Docs Changes:
Release Notes: Yes
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #35230]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

CC @missBerg @arkodg @denniskniep

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #37849 was opened by zhaohuabing.

see: more, trace.

@zhaohuabing

This comment was marked as resolved.

@zhaohuabing zhaohuabing closed this Jan 2, 2025
@denniskniep
Copy link
Copy Markdown
Contributor

denniskniep commented Jan 8, 2025

Hi @zhaohuabing,
can´t we add a new parameter code_verifier to the asyncGetAccessToken method.
This is then used here:

oauth_client_->asyncGetAccessToken(auth_code_, config_->clientId(), config_->clientSecret(),
redirect_uri, config_->authType());

The parameter is set by validateOAuthCallback return value (CallbackValidationResult), which retrieves it from a newly introduced code_verifier cookie (http-only, secure).

const CallbackValidationResult result = validateOAuthCallback(headers, path_str);

This newly introduced code_verifier cookie is set in the redirectToOAuthServer method.

@zhaohuabing
Copy link
Copy Markdown
Member Author

zhaohuabing commented Jan 9, 2025

@denniskniep Yes, you'r right about this. The asyncGetAcessToken is triggered by the IDP's redirect after user authentication, and we can retrieve the code verifier from the cookie. I missed that - thanks for pointing it out!

@zhaohuabing zhaohuabing reopened this Jan 9, 2025
@zhaohuabing zhaohuabing marked this pull request as draft January 9, 2025 04:19
@zhaohuabing zhaohuabing marked this pull request as ready for review January 9, 2025 09:07
@zhaohuabing zhaohuabing changed the title OAuth2: API for PKCE(Proof Key for Code Exchange) OAuth2: PKCE(Proof Key for Code Exchange) Jan 9, 2025
@zhaohuabing

This comment was marked as outdated.

@phlax
Copy link
Copy Markdown
Member

phlax commented Jan 11, 2025

... coverage check failed ...

should be fixed now

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing requested a review from wbpcode January 15, 2025 01:50
Signed-off-by: Huabing (Robin) Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing requested a review from denniskniep March 14, 2025 08:52
Signed-off-by: Huabing (Robin) Zhao <zhaohuabing@gmail.com>
@zhaohuabing
Copy link
Copy Markdown
Member Author

@denniskniep @wbpcode Whenever you have a moment, could you take another look at this PR? I'd love to wrap this up soon and move on to other OAuth2 improvement tasks. Really appreciate your time - thanks!

@zhaohuabing
Copy link
Copy Markdown
Member Author

/retest

@zhaohuabing
Copy link
Copy Markdown
Member Author

ping

Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for this great contribution and sorry for the delay.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 22, 2025

I think now you can ping the @phlax to merge the example PR?

@zhaohuabing
Copy link
Copy Markdown
Member Author

@wbpcode Do we need to wait until the example is updated in the bazel configuration?

wbpcode
wbpcode previously approved these changes Mar 25, 2025
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 25, 2025

@wbpcode Do we need to wait until the example is updated in the bazel configuration?

Yeah, I think so.

@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 25, 2025

i was hoping to do some docs cleanups before landing #38872 but i can do that in a follow up if its blocking

@zhaohuabing
Copy link
Copy Markdown
Member Author

zhaohuabing commented Mar 25, 2025

i was hoping to do some docs cleanups before landing #38872 but i can do that in a follow up if its blocking

@phlax Yeah, I would appreciate it if you could land #38872 sooner as it blocks this one.

@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 25, 2025

done

This reverts commit 7eeffc1.

Signed-off-by: Huabing (Robin) Zhao <zhaohuabing@gmail.com>
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@wbpcode wbpcode merged commit 0679277 into envoyproxy:main Mar 26, 2025
25 checks passed
@zhaohuabing zhaohuabing deleted the api-ouath-pkce branch March 26, 2025 04:08
mattklein123 pushed a commit that referenced this pull request Mar 30, 2025
Introduced by #37849

It is clear that `code_verifier_cookie_settings_` is not set to the
`FilterConfig`, and only the default is used.

Commit Message:
Additional Description:
Risk Level: low
Testing: unit test
Docs Changes:

Signed-off-by: Boteng Yao <boteng@google.com>
jewertow pushed a commit to jewertow/envoy that referenced this pull request Apr 2, 2025
This PR introduces support for PKCE(Proof Key for Code Exchange) in the
OAuth2 filter. This enhancement mitigates the risk of the authorization
code interception attacks.

Background: https://oauth.net/2/pkce/
RFC: [Proof Key for Code Exchange by OAuth Public
Clients](https://datatracker.ietf.org/doc/html/rfc7636)

Commit Message: 
Additional Description:
Risk Level: low
Testing: unit and integrate test,  also manually tested with AWS cognito
Docs Changes:
Release Notes: Yes
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes envoyproxy#35230]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

CC @missBerg @arkodg @denniskniep

---------

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing (Robin) Zhao <zhaohuabing@gmail.com>
jewertow pushed a commit to jewertow/envoy that referenced this pull request Apr 2, 2025
)

Introduced by envoyproxy#37849

It is clear that `code_verifier_cookie_settings_` is not set to the
`FilterConfig`, and only the default is used.

Commit Message:
Additional Description:
Risk Level: low
Testing: unit test
Docs Changes:

Signed-off-by: Boteng Yao <boteng@google.com>
agrawroh pushed a commit to agrawroh/envoy that referenced this pull request Apr 9, 2025
This PR introduces support for PKCE(Proof Key for Code Exchange) in the
OAuth2 filter. This enhancement mitigates the risk of the authorization
code interception attacks.

Background: https://oauth.net/2/pkce/
RFC: [Proof Key for Code Exchange by OAuth Public
Clients](https://datatracker.ietf.org/doc/html/rfc7636)

Commit Message: 
Additional Description:
Risk Level: low
Testing: unit and integrate test,  also manually tested with AWS cognito
Docs Changes:
Release Notes: Yes
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes envoyproxy#35230]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

CC @missBerg @arkodg @denniskniep

---------

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing (Robin) Zhao <zhaohuabing@gmail.com>
agrawroh pushed a commit to agrawroh/envoy that referenced this pull request Apr 9, 2025
)

Introduced by envoyproxy#37849

It is clear that `code_verifier_cookie_settings_` is not set to the
`FilterConfig`, and only the default is used.

Commit Message:
Additional Description:
Risk Level: low
Testing: unit test
Docs Changes:

Signed-off-by: Boteng Yao <boteng@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deps Approval required for changes to Envoy's external dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth2 filter: Proof Key for Code Exchange (PKCE)

6 participants